﻿<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>登录</title>
    <link rel="stylesheet" href="/lib/layui-v2.8.0/css/layui.css" media="all">
    <style>
        html {
            height: 100%;
            overflow-y: hidden;
        }

        .login-form {
            background-color: #fff;
            width: 320px;
            padding: 50px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }

        #particles-js {
            position: absolute;
            top: 0;
            width: 100%;
            z-index: -1;
            background: #aaa;
        }
    </style>
</head>
<body>
    <!-- 粒子背景 -->
    <div id="particles-js"></div>
    <!-- 登录表单 -->
    <form class="layui-form layui-panel login-form" autocomplete="off">
        <h1 class="login-title">
            <img style="height: 30px" src="img/logo.png" alt="logo" />
            <span>用户登录</span>
        </h1>
        <!-- 用户名 -->
        <div class="layui-form-item">
            <i class="layui-icon layui-icon-username"></i>
            <input type="text" name="username" placeholder="请输入用户名" class="layui-input" lay-verify="required" lay-reqText="请输入用户名" />
        </div>
        <!-- 密码 -->
        <div class="layui-form-item">
            <i class="layui-icon layui-icon-password"></i>
            <input type="password" name="password" placeholder="请输入密码" class="layui-input" lay-verify="required" lay-reqText="请输入密码" />
        </div>
        <!-- 验证码 -->
        <div class="layui-form-item">
            <i class="layui-icon layui-icon-vercode"></i>
            <input type="text" name="captcha" placeholder="请输入验证码" class="layui-input" lay-verify="required" lay-reqText="请输入验证码" />
            <img id="captcha" src="img/captcha.jpg" alt="验证码生成失败！" />
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-normal layui-btn-fluid" id="submit" type="button" lay-submit lay-filter="login"> 登录 </button>
        </div>
    </form>
    <script src="/lib/layui-v2.8.0/layui.js" charset="utf-8"></script>
    <script src="/lib/particles/particles.min.js"></script>
    <script src="/lib/particles/app.js"></script>
    <script>
        layui.use(["form", "jquery"], function () {
            const form = layui.form;
            const $ = layui.jquery;
            //监听提交
            form.on("submit(login)", function (data) {
                //调用登录接口
                window.location = "/home/index";
            });
            //按下回车登录
            $("body").on("keyup", (e) => {
                if (e.which === 13) {
                    $("#submit").trigger("click");
                }
            });
            //点击刷新验证码
            $("#captcha").on("click", (e) => {
                e.target.src += "?" + Math.random();
            });
        });
    </script>
</body>
</html>
